import {Injectable} from "@angular/core";
import {HttpService} from "../HttpService";
import {ResponseData} from "../model/ResponseData";
import {Http} from "@angular/http";
import {JSSBDownloadFile} from "../model/JSSBDownloadFile";
import {ms_article} from "../model/ms_article";
import {ArticleTypeEnum} from "../model/ArticleTypeEnum";


/**
 * 获得下载链接
 */
@Injectable()
export class ArticleService extends HttpService{

    protected listUrl:string="GetArticlesList";

    protected fromIDUrl:string="GetArticle";

    protected createURL:string="CreateArticle";

    public data:ms_article= new ms_article();


    constructor(private http:Http){super()};


   public getArticlesList(type:ArticleTypeEnum,condition:string=null):Promise<ResponseData<ms_article[]>>{

       return this.http.get(this.prefix + this.listUrl+"?type="+ArticleTypeEnum[type]+"&condition="+condition)
            .map(response => {
                return  response.json() as ResponseData<ms_article[]>;
            }).toPromise();
    }


    public getAnnouncement(id:number):string{
        return this.prefix+this.fromIDUrl+"?id="+id;
    }


    public createArticle(model:ms_article):Promise<ResponseData<boolean>>{
        return this.http.post(this.prefix + this.createURL,model)
            .map(response => {
                return  response.json() as ResponseData<boolean>;
            }).toPromise();
    }




}
